from django.db import models
from django.utils import timezone


class Comment(models.Model):
    name = models.CharField('名字', max_length=50)
    qqnumber = models.CharField('QQ', max_length=50, default="-1")
    email = models.EmailField('邮箱')
    url = models.URLField('网址', blank=True)
    picurl = models.URLField('头像', blank=True, default="https://ling_boogie.gitee.io/peasonal_pic/default_use.png")
    text = models.TextField('内容')
    created_time = models.DateTimeField('创建时间', default=timezone.now)

    post = models.ForeignKey('blogApp.Post', verbose_name='文章', on_delete=models.CASCADE)

    platform = models.CharField('platform', max_length=50, default="universe")
    browser = models.CharField('browser', max_length=50, default="SBIE")

    class Meta:
        verbose_name = '评论'
        verbose_name_plural = verbose_name

    def __str__(self):
        return '{}: {}'.format(self.name, self.text[:20])


class sonComment(models.Model):
    name = models.CharField('名字', max_length=50)
    qqnumber = models.CharField('QQ', max_length=50, default="-1")
    email = models.EmailField('邮箱')
    url = models.URLField('网址', blank=True)
    picurl = models.CharField('头像', max_length=300, blank=True,
                              default="https://ling_boogie.gitee.io/peasonal_pic/default_use.png")
    text = models.TextField('内容')
    created_time = models.DateTimeField('创建时间', default=timezone.now)
    p_comment = models.ForeignKey(Comment, verbose_name='父评论', on_delete=models.CASCADE)

    platform = models.CharField('platform', max_length=50, default="universe")
    browser = models.CharField('browser', max_length=50, default="SBIE")

    class Meta:
        verbose_name = '回复'
        verbose_name_plural = verbose_name

    def __str__(self):
        return '{}: {}'.format(self.name, self.text[:20])
